package cn.com.fuhuitong.main.mine.ui.activity

import android.annotation.SuppressLint
import androidx.lifecycle.Observer
import cn.com.fuhuitong.R
import cn.com.fuhuitong.aroute.ARouteConstance
import cn.com.fuhuitong.http.HttpResponseStatus
import cn.com.fuhuitong.main.ItemViewType
import cn.com.fuhuitong.main.base.ViewModeActivity
import cn.com.fuhuitong.main.mine.adapter.IncomeListAdapter
import cn.com.fuhuitong.main.mine.adapter.ShareListAdapter
import cn.com.fuhuitong.main.mine.entity.IncomeCenter
import cn.com.fuhuitong.main.mine.vm.IncomeViewModel
import cn.com.fuhuitong.utils.SpanUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import kotlinx.android.synthetic.main.activity_mine_income.*


@Route(path = ARouteConstance.ACTIVITY_URL_MINE_INCOME)
class MineIncomeActivity : ViewModeActivity<IncomeViewModel>() {

    private lateinit var mIncomeListAdapter: IncomeListAdapter

    override fun viewModel(): IncomeViewModel = createViewModel()

    override val layoutResId: Int
        get() = R.layout.activity_mine_income

    override fun initView() {

        image_mine_share_back.setOnClickListener {
            this.finish()
        }

        this.initViewRecyclerAdapter(
            recycler_mine_income_list, arrayOf(ItemViewType.INCOME_LIST)
        )

        delegateAdapter.addAdapter(
            IncomeListAdapter(this, LinearLayoutHelper())
                .apply { mIncomeListAdapter = this }
        )

        text_mine_income_withdraw.setOnClickListener {
            ARouter.getInstance().build(ARouteConstance.ACTIVITY_URL_MINE_WITHDRAW)
                .withInt("actionType",1)
                .navigation()
        }

    }

    override fun initViewMode() {

        viewModel.mineIncomeCenterDataLiveData.observe(this, Observer { response ->
            handlerResponseLoading(response.status, response.statusTip)
            if (response.status != HttpResponseStatus.Status.SUCCESS)
                return@Observer
            response.response?.data?.let {
                fillData(it)
            }
        })

        viewModel.mineIncomeListDataLiveData.observe(this, Observer { response ->
            //handlerResponseEmpty(response.status, response.statusTip)
            if (response.status != HttpResponseStatus.Status.SUCCESS)
                return@Observer
            response.response?.data?.let {
                mIncomeListAdapter.setAddDataNew(it)
            }
        })
    }

    override fun initData() {
        viewModel.orderStoreCommission()
        viewModel.orderStoreOrder()
    }

    @SuppressLint("SetTextI18n")
    private fun fillData(centerEntity: IncomeCenter) {
        text_mine_income_price.text = SpanUtils.setMoneyStyle(centerEntity.store_distribution_price)
        text_mine_income_level_health.text = SpanUtils.setMoneyStyle(centerEntity.last_month)
        text_mine_income_level_home.text = SpanUtils.setMoneyStyle(centerEntity.this_month_price)
        text_mine_income_level_flagship.text = centerEntity.this_month_goods.toString()
//        if (centerEntity.list.isEmpty())
//            return
//        shareListAdapter.setAddDataNew(centerEntity.list)
    }


}